	// 定义一个checkBox
	showProgress('加载数据，请稍候...');//显示进度条
	
	setTimeout( function() {
		
		var sm = new Ext.grid.CheckboxSelectionModel({
			singleSelect : false
		});
		sm.handleMouseDown = Ext.emptyFn;
		
		// 定义一个ColumnModel，表头中有二十列
		var cm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), sm,  
					  	{header:'销售ID',dataIndex:'idt_salesorders_h'},       
						{header:'价目表',dataIndex:'namelist_name'},            
						{header:'运输方法',dataIndex:'shipping_method_id'},    
						{header:'运费承担方式',dataIndex:'freight_terms_id'},  
						{header:'公司名称',dataIndex:'company_name'}, 
						{header:'客户名称',dataIndex:'customer_name'},               
						{header:'经办人',dataIndex:'pesponsible'},        
						{header:'输入日期',dataIndex:'oper_date'},        
						{header:'输入人',dataIndex:'created_user'},             
						{header:'更新日期',dataIndex:'last_update_date'},      
						{header:'更新人用户',dataIndex:'last_update_user'},       
						{header:'是否取消',dataIndex:'cancelled_flag'},        
						{header:'是否未结',dataIndex:'open_flag'},             
						{header:'会计是否登记',dataIndex:'booked_flag'},       
						{header:'销售员',dataIndex:'salesre_person'},             
						{header:'销售渠道',dataIndex:'meaning'},   
						{header:'工作流状态代码',dataIndex:'flow_status_code'},
						{header:'工作状态审核人',dataIndex:'flow_status'}, 
						{header:'订单(合同)金额',dataIndex:'order_money'},     
						{header:'备注',dataIndex:'remark'} 
						                                                                                                                                      
 		]);
 			var ds = new Ext.data.Store({
			baseParams : {
				trancode : '15110'
			},
			proxy : new Ext.data.HttpProxy({
				url : '../' + WebServiceUrl
			}),
			reader : new Ext.data.JsonReader({
				totalProperty : 'totalProperty',
				root : 'root'
			}, [
						{name:'idt_salesorders_h'},       
						{name:'namelist_name'},            
						{name:'shipping_method_id'},    
						{name:'freight_terms_id'},  
						{name:'company_name'},  
						{name:'customer_name'},              
						{name:'pesponsible'},        
						{name:'oper_date'},     
						{name:'created_user'},             
						{name:'last_update_date'},      
						{name:'last_update_user'},       
						{name:'cancelled_flag'},        
						{name:'open_flag'},             
						{name:'booked_flag'},       
						{name:'salesre_person'},             
						{name:'meaning'},   
						{name:'flow_status_code'},
					    {name:'flow_status'}, 
					    {name:'order_money'},     
						{name:'remark'}          
 		])});
			cm.defaultSortable = true; // 设置列可排序
			var grid = new Ext.grid.GridPanel({
			el : 'grid',
			id : 'salesordersd_form',
			ds : ds,
			cm : cm,
			// 定义分页
			bbar : new Ext.PagingToolbar({
				pageSize : App.pageSize,
				store : ds,
				displayInfo : true,
				displayMsg : '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
				emptyMsg : "没有记录"
			}),	            
			 sm: new Ext.grid.RowSelectionModel({	                
			 singleSelect: true,	                
			 listeners: {	                    
			 	rowselect: function(sm, row, rec) {	                        
			 		Ext.getCmp("salesordersd_form").getForm().loadRecord(rec);	                   
			  	}	               
			   }	           
			 }),
			 title : "业务订单调整",
			 
			// inline toolbars
			tbar : [{
					text : "起始时间:",
					id : "111"
					
				}, {
					xtype : "datefield",
					format:'Y-m-d',
					id : 'keywords',					
					selectOnFocus : true,
					text:showDate()
				},{
					text : "截止时间:",
					id : "222"
					
				},{
					xtype : "datefield",
					format:'Y-m-d',
					id : 'keywords2',					
					selectOnFocus : true
				},{
				text : '查询',
				tooltip : '查询',
				handler : doSearch,
				iconCls : 'search'
			}, '-', {
				text : '作废',
				tooltip : '作废',
				handler : doDel,
				iconCls : 'remove'
			}],
			height : 466,		
			bodyStyle:'width:100%',
		     listeners: {		        	
		     render: function(g) {		        		
		     g.getSelectionModel().selectRow(0);		        	
		     },		        	
		     delay: 10 	        
	 		}
		});
		
		
//		alert("---------------------------------------------");
		 var cmm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), sm,  
					  {header:'计划发货日期',dataIndex:'request_date'}, 
 					  {header:'计划理货日期',dataIndex:'schedule_ship_date'},
 					  {header:'计划到货日期',dataIndex:'schedule_arrival_date'},
 					  {header:'交货名称',dataIndex:'goodsname'},
 					  {header:'产品规格',dataIndex:'spec'},
 					  {header:'价格',dataIndex:'sale_price'},  
 					  {header:'订单数量',dataIndex:'order_quantity_uom'},
 					  {header:'长',dataIndex:'attrib1'},
 					  {header:'长单位',dataIndex:'attrib1_unit'},
 					  {header:'门片宽',dataIndex:'attrib2'},
 					  {header:'宽单位',dataIndex:'attrib2_unit'},
 					  {header:'门片高',dataIndex:'attrib3'},
 					  {header:'高单位',dataIndex:'attrib3_unit'},
 					  {header:'款式',dataIndex:'attrib4'},
 					  {header:'款式单位',dataIndex:'attrib4_unit'},
 					  {header:'属性',dataIndex:'attrib5'},
 					  {header:'属性单位',dataIndex:'attrib5_unit'}                                                                                                                                   
 		]);
 		cmm.defaultSortable = true;
 		
 			var dss = new Ext.data.Store({
			baseParams : {
				trancode : '151181'			
			},
			proxy : new Ext.data.HttpProxy({
				url : '../' + WebServiceUrl
			}),
			reader : new Ext.data.JsonReader({
			totalProperty : 'totalProperty',
			root : 'root'
			}, [
				{name:'request_date'}, 
				{name:'schedule_ship_date'},
				{name:'schedule_arrival_date'},
				{name:'goodsname'},
				{name:'spec'},
				{name:'sale_price'},  
				{name:'order_quantity_uom'},
				{name:'attrib1'},
				{name:'attrib1_unit'},
				{name:'attrib2'},
				{name:'attrib2_unit'},
				{name:'attrib3'},
				{name:'attrib3_unit'},
				{name:'attrib4'},
				{name:'attrib4_unit'},
				{name:'attrib5'},
				{name:'attrib5_unit'}                    
		])});
 		
 			var gridForm2 = new Ext.form.FormPanel({        
		 	id: gridForm2,
		 	name:gridForm2,       
		  	frame: true,                
		  	title: '销售明细',        
		  	bodyStyle:'padding:5px',               
		  	layout: 'column',
			 items: [{            
			 	columnWidth:1.2,            
			 	layout: 'fit',            
			 	items: {	            
			 		xtype: 'grid',	            
			 		ds: dss,	            
			 		cm: cmm,
			 		bbar : new Ext.PagingToolbar({
						pageSize : App.pageSize,
						store : dss,
						displayInfo : true,
						displayMsg : '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
						emptyMsg : "没有记录"
					}),	            
			 		sm: sm,                       
			 		height: 200,
			 		autoWidth:true,	                       
			 		border: true,		        
			 		listeners: {		        	
			 			render: function(g) {		        		
			 			g.getSelectionModel().selectRow(0);		        	
			 			}		        	    
			 		}
				 }         
			  }]			  
			});
			
		//显示 grid
		grid.render();	
		gridForm2.render(document.body);
					
				
		//双击事件
		grid.on('rowdblclick', function(grid, rowIndex, e) {
			new App.EditSalesOrders(ds, grid, rowIndex);	
		});

		//单击事件
		grid.on('rowclick', function(grid, t,rowIndex,e) {
		SearchSalesOrdersd();
		dss.load({
			params : {
				start : 0,
				limit : App.pageSize
				}
			});
		});

		
		//加载分页参数
		ds.load({
			params : {
				start : 0,
				limit : App.pageSize
			}
		});		
       //获得系统当前日期
       function showDate()    
      {    
        var today = new Date();    
        var day = today.getDate();    
        var month = today.getMonth() + 1;    
        var year = today.getYear();    
        var date = year + "-" + month + "-" + day;    
        document.getElementsByName(文本框的name)[0].value = date;    
      } ;
		
		
		
		//根据单头Id查询销售明细
		function SearchSalesOrdersd(){
		  var record = grid.getSelectionModel().getSelected();
	 	  dss.baseParams = {
           		id:record.get('idt_salesorders_h'),
           		trancode:'151181'
           }};

		/**编辑**/
		function doEdit() {
					var rows = grid.getSelectionModel().getSelections();// 返回值为 Record 数组 
					if (rows.length == 0 || rows.length >= 2) {
						Ext.MessageBox.alert('警告', '请选择一条信息，进行修改!');
					} else {						
						//修改操作						
					}	
				}
		
		//根据时间查询业务单头
		function doSearch(){
	 	  var keywords = Ext.get('keywords').dom.value;
	 	  var keywords2 = Ext.get('keywords2').dom.value;
	 	  ds.baseParams = {
           		keywords:keywords,
           		keywords2:keywords2,
           		trancode:'15110'
           };
          ds.load({	params : {start : 0,limit : App.pageSize}});	 	
	 }
	 //注册回车查询事件
	 Ext.getCmp('keywords2').on('specialkey',doSearch);		
		
		/**删除**/
		function doDel() {
					var rows = grid.getSelectionModel().getSelections();// 返回值为 Record 数组 
					if (rows.length == 0) {
						Ext.MessageBox.alert('警告', '最少选择一条信息，进行删除!');
					} else {
						Ext.MessageBox.confirm('提示框', '将会删除整张单据，您确定要进行该操作？</br></br>', function(btn) {
							if (btn == 'yes') {
								if (rows) {
									for (var i = 0; i < rows.length; i++) {
										//删除
										Ext.Ajax.request({
											url : '../' + WebServiceUrl,
											params : {
												trancode : '15114',
												id : rows[i].get("idt_salesorders_h")
											},
											success : function(result) {
												json = Ext.util.JSON
														.decode(result.responseText);
												if (json.success) {
													Ext.MessageBox.alert('操作成功',
															json.message);
															ds.load({params:{start:0, 
																	 limit:App.pageSize}});
															Ext.getCmp(winid).close();
												} else {
													Ext.MessageBox.alert('操作失败',
															json.message);
												}
											}
										});
									}
								}
							}
							ds.load({
								params : {
									start : 0,
									limit : App.pageSize
								}
							});
						})
					}	
				}		
	Ext.MessageBox.hide();//隐藏进度条
	},1000)
     window.onresize=function(){
        grid.setWidth(0);
        grid.setWidth(orgGrid.getComputedWidth());
};
	
})
